import type { ContextOpts } from './types'

export type AuthContext = Awaited<ReturnType<typeof createAuthContext>>
export function createAuthContext({
  req,
  res,
}: ContextOpts) {
  const getUser = () => {
    if (req.headers.authorization !== 'secret')
      return null

    return {
      name: 'alex',
    }
  }

  return {
    req,
    res,
    user: getUser(),
  }
}
